Skip to content

Conversation

@cpsievert
Copy link
Contributor

@cpsievert cpsievert commented Feb 9, 2026

Summary

  • When a custom prompt_template is provided that doesn't contain Mustache references to {{schema}}, the expensive get_schema() call is now skipped entirely
  • This allows users with large databases to avoid slow startup by providing their own prompt template that includes schema information inline (or omits it)
  • Zero new API surface — works through the existing prompt_template parameter

Closes #208

How it works

In QueryChatSystemPrompt.__init__() (both R and Python), a regex check detects whether the template references schema as a Mustache variable in any form ({{schema}}, {{{schema}}}, {{#schema}}, {{^schema}}). If not found, get_schema() is never called and schema is set to an empty string.

Usage

# Python — provide a prompt template without {{schema}} to skip inference
qc = QueryChat(
    data_source=my_large_db,
    table_name="my_table",
    prompt_template="You are a data assistant. The database has columns: id, name, value...",
)
# R — same approach
qc <- QueryChat$new(
  my_large_db,
  "my_table",
  prompt_template = "You are a data assistant. The database has columns: id, name, value..."
)

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…hema

When a custom prompt_template is provided that doesn't contain any
Mustache references to {{schema}}, the expensive get_schema() call
(which runs full table scans for column statistics) is now skipped
entirely. This allows users with large databases to avoid the slow
startup by providing their own prompt template without {{schema}}.

Uses a regex to detect schema references in any Mustache form:
{{schema}}, {{{schema}}}, {{#schema}}, {{^schema}}.

Closes #208

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@cpsievert cpsievert force-pushed the feature/system-prompt-override branch from a7bc7fb to ec088ab Compare February 9, 2026 19:59
@cpsievert cpsievert changed the title feat: Add system_prompt parameter to bypass schema inference feat: Skip schema inference when prompt template doesn't reference schema Feb 9, 2026
@cpsievert cpsievert changed the title feat: Skip schema inference when prompt template doesn't reference schema fix: Skip schema inference when prompt template doesn't reference schema Feb 9, 2026
@cpsievert cpsievert requested a review from gadenbuie February 9, 2026 20:05
Copy link
Contributor

@gadenbuie gadenbuie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's nice that this approach works the same way in Python and R 😄

The ruff PLW0108 lint error (unnecessary lambda) in test_base.py was
causing format checks to fail. The griffe 2.0.0 release broke
quartodoc 0.11.1's docstring parsing, so pin griffe<2 until quartodoc
adds support.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@cpsievert cpsievert merged commit 255c86b into main Feb 11, 2026
17 checks passed
@cpsievert cpsievert deleted the feature/system-prompt-override branch February 11, 2026 21:15
@jperone
Copy link

jperone commented Feb 12, 2026

Thank you for the quick change, this works for me now. Appreciate the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(pkg-R) Encountering latency with querychat server when using complex database

3 participants